package yunquan.wang.base.web.taglib;

import java.util.Iterator;
import java.util.Set;

import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;

import yunquan.wang.base.spring.SpringContextHolder;
import yunquan.wang.modules.base.entity.CodeValue;
import yunquan.wang.modules.base.service.AppCodeService;

public class WebFunctions {
	/**
	 * 将Iterable 转换为Iterator
	 * 
	 * @param iterable
	 * @return
	 */
	public static Iterator iterableChange(Iterable iterable) {
		if(iterable==null)
			return null;
		return iterable.iterator();
	}

	/**
	 * 获取指定代码类型的代码列表
	 * @param codeType 代码类型
	 * @return
	 */
	public Set<CodeValue> getCodeSet(String codeType)
	{
		AppCodeService codeService=SpringContextHolder.getBean(AppCodeService.class);
	    return	codeService.getAllCodeValue(codeType);
	}
	
	
	public Object getCodeValue(String codeType,String code)
	{
		AppCodeService codeService=SpringContextHolder.getBean(AppCodeService.class);
	    return	codeService.getCodeValue(codeType, code);
	}
	
	/**
	 * 获取排序的第一个order
	 * 
	 * @param sort
	 * @return
	 */
	public static Order firstOrder(Sort sort) {
		if (sort == null)
			return null;
		else {
			Iterator<Order> it = sort.iterator();
			if (it.hasNext())
				return it.next();
			else
				return null;
		}
	}

}
